/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package core.threads.server;
import core.messages.Msg;
import core.messages.client.creation.Msg_Connect;
import core.messages.client.creation.Msg_Role_Select;
import core.messages.client.inGame.Msg_Response;
import core.messages.server.inGame.Msg_Screen_Refresh;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.LinkedBlockingQueue;
import models.Game;

/**
 *
 * @author Invince
 */
public class Server_Public_MsgBox {
/*----------Attributs-------------------*/
    /**-----Message Box------**/
        /***---Communication部分---***/
        public static BlockingQueue<Msg>  msgBox_Server_Send_Msg=new LinkedBlockingQueue<Msg>();
        public static BlockingQueue<Msg>  msgBox_Server_Rcv_Msg=new LinkedBlockingQueue<Msg>();
        /***---Server内核部分---***/
            /****--Creation---****/
        public static BlockingQueue<Msg_Connect> msgBox_Server_Add_Game=new LinkedBlockingQueue<Msg_Connect>();
        public static BlockingQueue<Next_Step> msgBox_Server_Next_Step=new ArrayBlockingQueue<Next_Step>(1);//定容量的就用Array...其实Linked也可以但是效率低
            public static class Next_Step{//empty class
                public Next_Step(){}
            }
         public static BlockingQueue<Previous_Step> msgBox_Server_Previous_Step=new ArrayBlockingQueue<Previous_Step>(1);//定容量的就用Array...其实Linked也可以但是效率低
            public static class Previous_Step{//empty class
                public Previous_Step(){}
            }

         public static BlockingQueue<CaraNb_Config> msgBox_Server_CaraNb_Config=new ArrayBlockingQueue<CaraNb_Config>(1);//定容量的就用Array...其实Linked也可以但是效率低
            public static class CaraNb_Config{//之所以静态，因为在外部被调用(T_Server_Cara_Config）
                protected int nbMajesty;//恒等于1
                protected int nbLoyal;
                protected int nbRebel;
                protected int nbSpy;
                public CaraNb_Config(){}
                public CaraNb_Config(CaraNb_Config caraNbConfig){
                    this.nbMajesty=caraNbConfig.getNbMajesty();
                    this.nbLoyal=caraNbConfig.getNbLoyal();
                    this.nbRebel=caraNbConfig.getNbRebel();
                    this.nbSpy=caraNbConfig.getNbSpy();
                }
                public CaraNb_Config(int nbLoyal, int nbRebel, int nbSpy) {
                    this.nbMajesty=1;
                    this.nbLoyal = nbLoyal;
                    this.nbRebel = nbRebel;
                    this.nbSpy = nbSpy;
                }
                public int getNbLoyal() {return nbLoyal;}
                public int getNbMajesty() {return nbMajesty;}
                public int getNbRebel() {return nbRebel;}
                public int getNbSpy() {return nbSpy;}
            }

        public static BlockingQueue<Msg_Role_Select> msgBox_Server_Role_Select=new LinkedBlockingQueue<Msg_Role_Select>();
            /****---InGame----****/
        public static BlockingQueue<Deck_Process> msgBox_Deck_Process=new LinkedBlockingDeque<Deck_Process>();
            public static class Deck_Process{
                protected int sourceId;
                protected int sourceDeckId;
                public Deck_Process(int sourceId, int sourceDeckId) {
                    this.sourceId = sourceId;
                    this.sourceDeckId = sourceDeckId;
                }
                public int getSourceDeckId() {return sourceDeckId;}
                public void setSourceDeckId(int sourceDeckId) {this.sourceDeckId = sourceDeckId;}
                public int getSourceId() {return sourceId;}
                public void setSourceId(int sourceId) {this.sourceId = sourceId;}
            }

            public static class Deck_Process_Draw extends Deck_Process{
                protected int targetId;
                protected int targetDeckId;
                protected int nbCard;
                public Deck_Process_Draw(int sourceId, int sourceDeckId,/* int targetId, int targetDeckId,*/ int nbCard) {
                    super(sourceId, sourceDeckId);
//                    this.targetId = targetId;
//                    this.targetDeckId = targetDeckId;
                    this.nbCard = nbCard;
                }
                public int getNbCard() {return nbCard;}
                public void setNbCard(int nbCard) {this.nbCard = nbCard;}
//                public int getTargetDeckId() {return targetDeckId;}
//                public void setTargetDeckId(int targetDeckId) {this.targetDeckId = targetDeckId;}
//                public int getTargetId() {return targetId;}
//                public void setTargetId(int targetId) {this.targetId = targetId;}
            }

            public static class Deck_Process_Move extends Deck_Process{
                protected int cardId;
                public Deck_Process_Move(int sourceId, int sourceDeckId,int cardId) {
                    super(sourceId, sourceDeckId);
                    this.cardId = cardId;
                }
                public int getCardId() {return cardId;}
                public void setCardId(int cardId) {this.cardId = cardId;}
            }

    public static BlockingQueue<Msg_Response> msgBox_Server_Response=new LinkedBlockingQueue<Msg_Response>();

/*----------Public functions------------*/
    /**
     * 刷新屏幕
     * @return
     */
    public synchronized static boolean refreshScreen(){
        Game game;
        synchronized(Server_Public_Data.semaGame){
            game=Server_Public_Data.game;
        }
        Msg_Screen_Refresh msgScreen=new Msg_Screen_Refresh("Server",game);
        return msgBox_Server_Send_Msg.offer(msgScreen);
    }
/*----------Private functions-----------*/
/*----------Constructor-----------------*/
/*----------Gets and sets---------------*/
}
